package com.datang.pet.api.talkController;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-06-14 09:42
 * @notify
 * @version 1.0
 */

import com.datang.pet.common.response.Result;
import com.datang.pet.common.utils.MD5;
import com.datang.pet.common.utils.StringUtils;
import com.datang.pet.service.TalkService;
import com.datang.pet.vo.ComplainTalkRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ComplainTalkController {

    @Autowired
    private TalkService talkService;

    @PostMapping("/complainTalk")
    public Result complainTalk(@RequestBody ComplainTalkRequest complainContent) throws Exception {


        String userId = complainContent.getUserId();

        String talkId = complainContent.getTalkId();

        String content = complainContent.getComplainContent();


        if (!StringUtils.isNUll(talkId)) {
            throw new Exception("喵文id不能为空");
        }
        if (!StringUtils.isNUll(userId)) {
            throw new Exception("用户id不能为空");
        }
        if (!StringUtils.isNUll(content)) {
            throw new Exception("举报内容不能为空");
        }
        //md5解密userId(普通用户)
        try {
            userId = (MD5.decryptData(userId));
        } catch (Exception e) {
            throw new Exception("userId解密出错！");
        }
        talkService.complainTalk(userId, talkId, content);
        return Result.ok("成功");
    }
}
